DAY19:Beginner Series #3 Sum of Numbers


Posted by birdbirdmurmur on 2023-08-01

題目連結

Beginner Series #3 Sum of Numbers

解法

function getSum(a, b)
{
   const start = Math.min(a, b);
   const end = Math.max(a, b);
   let sum = 0;
   for (let i = start; i <= end; i++) {
     sum += i;
   }
   return sum;
}

心得

先找出最大和最小值
再利用迴圈一個一個加起來


#javascript #Codewars #Math.max #Math.min







Related Posts

Oracle SQL / MSSQL 常用語法比較

Oracle SQL / MSSQL 常用語法比較

Jest - mock read-only data

Jest - mock read-only data

HTTP 協議 / 請求&Cache / 回應&Content-Type

HTTP 協議 / 請求&Cache / 回應&Content-Type


Comments